# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=release-cli
pkgver=0.15.0
pkgrel=1
pkgdesc="Gitlab Release CLI"
arch=(loong64 x86_64)
url="https://gitlab.com/gitlab-org/release-cli"
license=(MIT)
depends=(glibc)
makedepends=(go)
options=(debug)
source=($pkgname-$pkgver.tar.gz::https://gitlab.com/gitlab-org/$pkgname/-/archive/v$pkgver/$pkgname-v$pkgver.tar.gz)
sha512sums=('4665cc7607cb7ee752fd012390778d28f41789f540c09a3afb25884ac3d3911f1db49d99ea161f91f1ca77b46489f7bb1f4657b7eb0cf1b64edf3c3f0b429628')
b2sums=('6eeb6e1bd8838445248bfd57b8ff522e9d5790c02356cad64d095be484278d83cab988333c0270a42822e8864eb2d33f489a338a9fd0a613856676020c2c3ace')

prepare() {
  mkdir -vp $pkgname-v$pkgver/build
}

build() {
  cd $pkgname-v$pkgver
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"

  go build -o build/$pkgname ./cmd/$pkgname
}

package() {
  install -vDm 755 $pkgname-v$pkgver/build/$pkgname -t "$pkgdir/usr/bin/"
  install -vDm 644 $pkgname-v$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-v$pkgver/{CHANGELOG,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
  cd $pkgname-v$pkgver/docs
  find . -type f -iname "*.md" -exec install -vDm 644 {} "$pkgdir/usr/share/doc/$pkgname/"{} \;
}
